package com.anyonavinfo.cpaddemo.data.weatherinfo.source.remote;

import android.content.Context;
import android.content.Intent;

import com.anyonavinfo.cpaddemo.Application;
import com.anyonavinfo.cpaddemo.R;
import com.anyonavinfo.cpaddemo.data.weatherinfo.WeatherInfo;

import java.util.List;

/**
 * Created by ZuiC on 2017/2/4.
 */

public class WeatherInfoBeanHelper {

    public static WeatherInfo parseWeatherInfoBean(WeatherInfoBean weatherInfoBean){
        WeatherInfo weatherInfo = new WeatherInfo();
        Context context = Application.getContextObject();
        if (weatherInfoBean != null) {
            WeatherInfoBean.DataBeanX data1 = weatherInfoBean.getData();
            if (data1 != null) {
                WeatherInfoBean.DataBeanX.DetailBean detail = data1.getDetail();
                if (detail != null) {
                    WeatherInfoBean.DataBeanX.DetailBean.DataBean data2 = detail.getData();
                    if (data2 != null) {
                        List<WeatherInfoBean.DataBeanX.DetailBean.DataBean.WeatherListBean> weatherList = data2.getWeatherList();
                        if (weatherList != null && weatherList.size() > 0) {
                            WeatherInfoBean.DataBeanX.DetailBean.DataBean.WeatherListBean weatherListBean = weatherList.get(0);
                            if (weatherListBean != null) {
                                WeatherInfoBean.DataBeanX.DetailBean.DataBean.WeatherListBean.CurrentWeatherBean currentWeather = weatherListBean.getCurrentWeather();
                                if (currentWeather != null) {
                                    String weather = currentWeather.getWeather();
                                    String temperature = currentWeather.getTemperature().split("\\.")[0];
                                    //天气信息
                                    if (weather != null) {
                                        String[] stringArray = context.getResources().getStringArray(R.array.weather);
                                        int count;
                                        for (int i = 0; i < stringArray.length; i++) {
                                            if (i == 34) {
                                                count = i + 15;
                                            }else if (i > 34 ) {
                                                count = i + 18;
                                            }else {
                                                count = i;
                                            }
                                            if (weather.equals(count + "")) {
                                                weatherInfo.setCurWeatherType(stringArray[i]);
                                            }
                                        }
                                    }
                                    //当前温度信息
                                    if (temperature != null) {
                                        weatherInfo.setCurTemperature(temperature);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        return weatherInfo;
    }
}
